#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include "data/fileStorage.h"
#include "services/studentService.h"
#include <QtCharts>
#include <tests/test.h>


int main(int argc, char *argv[]) {
    QGuiApplication app(argc, argv);
    // QApplication app(argc, argv);

    // 测试API等
    Test::run();

    // 初始化数据存储
    auto *storage = new FileStorage("data/students.dat");

    // 测试API等
    Test::run();

    // 注册图表类型
    // qmlRegisterType<QChart>("QtCharts", 2, 0, "Chart");
    // qmlRegisterType<QPieSeries>("QtCharts", 2, 0, "PieSeries");
    // qmlRegisterType<QBarSeries>("QtCharts", 2, 0, "BarSeries");
    // qmlRegisterType<QBarSet>("QtCharts", 2, 0, "BarSet");
    // qmlRegisterType<QBarCategoryAxis>("QtCharts", 2, 0, "BarCategoryAxis");
    // qmlRegisterType<QValueAxis>("QtCharts", 2, 0, "ValueAxis");
    // qmlRegisterType<QHorizontalBarSeries>("QtCharts", 2, 0, "HorizontalBarSeries");


    // 初始化学生服务
    StudentService studentService(storage);

    // 设置 QML 样式
    QQuickStyle::setStyle("Fusion"); // 或 "Material", "Universal" 等
    qputenv("QML_STYLE", "Fusion");  // 与 QSS 兼容

    QQmlApplicationEngine engine;
    // 将服务暴露给QML
    engine.rootContext()->setContextProperty("StudentService", &studentService);

    // 加载主界面
    engine.load(QUrl(QStringLiteral("qrc:/src/ui/mainWindow.qml")));

    return QGuiApplication::exec();
}
